﻿@model CategoryDTO[]
@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote categories_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal categoriesAdd_btn">添加商品类别</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后除新添加的文章外所有操作无效，关闭页面所有数据重置</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold"> 4 </span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form categories_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>商品类别名称</th>
                            <th>创建日期</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="categories_content">
                        @foreach (var category in Model)
                        {

                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                        <i class="layui-icon"></i>
                                    </div>
                                </td>
                                <td>@category.Name</td>
                                <td>@category.CreateDateTime</td>
                                <td>
                                    <a class="layui-btn layui-btn-mini categories_edit"  data-id="?id=@category.Id"><i class="iconfont icon-edit"></i> 编辑</a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini categories_del" data-id="@category.Id">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page"></div>
                </div>
            </div>

        </div>
    </div>

</section>

@section FooterScript{
    <script type="text/javascript">

        var appConfig = {
            name: "categories",    //需要和页面名称对应
            title: "商品类别",    //显示的名称
            addUrl: "/Category/AddNew",   //添加弹框的路径
            editUrl: "/Category/Edit",      //修改弹框的路径
            $: "",
            layer: "",
            area: ['100%', '1000px'],

            //批量删除Ajax
            batchDel: function (data) {     //Array data 得到的是 需要删除的id
                data.each(function (index, value) {
                    console.log(value);


                    //todo:在此处添加批量删除记录的ajax

                });

            },
            del: function (data) {

                $ = appConfig.$;

                $.ajax({
                    url: "/Category/Delete",
                    type: "post",
                    dataType: "json",
                    data: { id: data },
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", { time: 1000, icon: 1 });
                        } else if (res.status == "redirect") {
                            location.href = res.msg;
                        } else if (res.status == "error") {
                            appConfig.layer.msg(res.errorMsg, { time: 1000, icon: 1 });
                        } else {
                            appConfig.layer.msg("错误", { time: 1000, icon: 2 });
                        }
                    }, error: function () {
                        layer.msg("请求出错");
                    }
                })
            }
        };
        layui.use(['jquery', 'layer', 'element', 'laypage'], function () {
            window.jQuery = window.$ = layui.jquery;
            window.layer = layui.layer;
            var element = layui.element(),
                laypage = layui.laypage;


            laypage({
                cont: 'page',
                pages: 10 //总页数
                ,
                groups: 5 //连续显示分页数
                ,
                jump: function (obj, first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    if (!first) {
                        //layer.msg('第 '+ obj.curr +' 页');
                    }
                }
            });

        });
    </script>
}